﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using static UIWindow.Domains.CustomDelegates;

namespace UIWindow.Lucifer
{
    public interface ICommunication
    {
        bool IsConnect { get; }
        List<byte> ByteCache { get; set; }
        /// <summary>
        /// 连接
        /// </summary>
        /// <returns></returns>
        bool Connect();
        /// <summary>
        /// 关闭连接
        /// </summary>
        void Close();
        void Read(CancellationTokenSource tokenSource);
        byte[] Read();
        void Write(byte[] bytes);
        /// <summary>
        /// 写入数据
        /// </summary>
        /// <param name="protocol"></param>
        /// <returns></returns>
        bool Write(IProtocol protocol);
        /// <summary>
        /// 读取一个结构体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="protocol"></param>
        /// <returns></returns>
        T ReadWrite<T>(IProtocol protocol) where T : class, new();
        void SetTimeout(int time);
        event DropAlarm DropAlarms;
    }
}
